package com.vanke.devops.api.controller.systeminfo;

import com.vanke.devops.api.base.AbstractController;
import com.vanke.devops.api.controller.endpoints.form.EndpointsForm;
import com.vanke.devops.api.controller.systeminfo.form.SysteminfoForm;
import com.vanke.devops.dal.model.SystemInfo;
import com.vanke.devops.domain.domain.schedulejob.param.ScheduleJobParam;
import com.vanke.devops.domain.domain.systeminfo.ISystemInfoService;
import com.vanke.devops.domain.domain.systeminfo.dto.SysteminfoDTO;
import org.springframework.beans.BeanUtils;
import org.springframework.web.bind.annotation.*;

import com.vanke.core.bean.ApiBaseResponse;
import com.vanke.core.bean.PagingResponse;


/**
 * <p>
 * 用户表  前端控制器
 * </p>
 *
 * @author 马子晋
 * @since 2018-08-07
 */
@RestController
@RequestMapping("/system_info")
public class SystemInfoController extends AbstractController<ISystemInfoService> {

    @GetMapping(value = "/page/{pageSize}/{pageNo}")
    public PagingResponse list(@RequestParam(value = "name",required = false) String name,
                               @RequestParam(value = "type",required = false) String type,
                               @PathVariable("pageSize") Integer pageSize,
                               @PathVariable("pageNo") Integer pageNo)  {
        return setResponse(service.queryPage(type,name,pageSize,pageNo));
    }

    @GetMapping(value = "/{id}")
    public ApiBaseResponse get(@PathVariable("id") Integer id)  {

        return super.setResponse(service.getInfo(id));
    }

    @PutMapping(value = "/{id}")
    public ApiBaseResponse update(@RequestBody SysteminfoForm form, @PathVariable("id") Integer id)  {
        SystemInfo systemInfo=this.getSystemInfo(form);
        systemInfo.setId(id);
        SysteminfoDTO systeminfoDTO=service.updateSystemInfo(systemInfo);
        return super.setResponse(systeminfoDTO);
    }

    @DeleteMapping(value = "/{id}")
    public ApiBaseResponse delete(@PathVariable("id") Integer id)  {
        service.deleteSystemInfo(id);
        return setResponse();
    }

    @PostMapping
    public ApiBaseResponse add(@RequestBody SysteminfoForm form)  {
        SystemInfo systemInfo=this.getSystemInfo(form);
        return setResponse(service.addSystemInfo(systemInfo));
    }

    private SystemInfo getSystemInfo(SysteminfoForm form){
        SystemInfo entity = new SystemInfo();
        entity.setName(form.getName());
        entity.setCover(form.getCover());
        entity.setAddress(form.getAddress());
        entity.setType(form.getType());
        entity.setLoginId(form.getLoginId());
        entity.setPassword(form.getPassword());
        entity.setIspublic(form.getIspublic());
        return entity;
    }
}
